//
//  PilotViewController.m
//  LHTourApp
//
//  Created by 千锋 on 15/12/23.
//  Copyright (c) 2015年 QianFeng. All rights reserved.
//

#import "PilotViewController.h"
#import "RootViewController.h"
@interface PilotViewController ()


@end

@implementation PilotViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createUI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)createUI
{
    UIScrollView * scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:scrollView];
    
    CGSize screenSize = [UIScreen mainScreen].bounds.size;
    // 添加图片到滚动视图里
    for (int index = 0; index<5; index++) {
        UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(index*screenSize.width, 0, screenSize.width, screenSize.height)];
         [self.view addSubview:scrollView];
        [scrollView addSubview:imageView];
       
        scrollView.backgroundColor = [UIColor orangeColor];
        
        // 添加图片
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"car%d.jpg",index+1]];
        // 判断是否是最后一张
        if (index == 4) {
            imageView.userInteractionEnabled = YES;
            UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
            button.frame = CGRectMake(screenSize.width/2-50, screenSize.height-100, 100, 50);
            [imageView addSubview:button];
            [button setTitle:@"开启旅行" forState:UIControlStateNormal];
            button.layer.borderWidth = 0.5;
            button.layer.cornerRadius = 5;
            
            button.titleLabel.font = [UIFont systemFontOfSize:20];
            [button setTitleColor:[UIColor colorWithRed:0.4 green:0.5 blue:0.2 alpha:1] forState:UIControlStateNormal];
            button.layer.borderColor = [UIColor orangeColor].CGColor;
            [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
        }
        
    }
    
    scrollView.contentSize = CGSizeMake(screenSize.width*5, screenSize.height);
    scrollView.pagingEnabled = YES;
    scrollView.bounces = NO;
    scrollView.showsVerticalScrollIndicator =NO;
    scrollView.showsHorizontalScrollIndicator=NO;
    
}

-(void)buttonClicked:(UIButton *)sender
{
    RootViewController * rootVC =[[RootViewController alloc]init];
    CATransition * transition = [CATransition animation];
    transition.duration = 2;
    transition.type = @"reveal";
    transition.subtype = @"fromRight";
    [self.view.superview.layer addAnimation:transition forKey:nil];
    UINavigationController * navi = [[UINavigationController alloc]initWithRootViewController:rootVC];
    self.view.window.rootViewController = navi;

}





@end
